//
//  WBMainController.swift
//  weibobo
//
//  Created by KIMI on 16/9/19.
//  Copyright © 2016年 KIMI. All rights reserved.
//

import UIKit

class WBMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置自定义tabbar
        let tabbar = WBTabBar()
        
        //设置代理
        tabbar.WBDelegate = self
        
        //传入闭包
        tabbar.composeBtnClosure = { [weak self] in
            
            print("闭包调用")
            
        }
        //kvC
        setValue(tabbar, forKey: "tabBar")
        
        UITabBar.appearance().tintColor = UIColor.orange
        
        addChildViewController(childController: WBHomeController(), title: "主页", imgName: "tabbar_home")
        addChildViewController(childController: WBMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(childController: WBDiscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(childController: WBProfileController(), title: "我的", imgName: "tabbar_profile")
        
    }
    
    //添加子视图控制器的重载
    func addChildViewController(childController: UIViewController,title: String, imgName: String) {
        
        //设置tabarItem图片,文字
        childController.tabBarItem.image = UIImage(named: imgName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
        //设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
        
//        childController.tabBarItem.title = title
//        childController.navigationItem.title =title
        
        childController.title = title
        //创建导航控制器
        let nav = WBNavigationController(rootViewController: childController)
        
        //添加子视图控制器
        addChildViewController(nav)
        
    }

  

}

extension WBMainController: WBTabarDelegate{
    
    func didSelectedComposeBrn() {
        
        print("代理调用")
    }
    
}
